import sys
import os
import configparser
from loguru import logger
from test_setting import LOCAL_PATH

logger.remove()  # 清除它的默认设置设置
fmt = '[{time}][{level}][{file.path}:line:{line}:function_name:{function}] ||msg={message}'
# level file function module time message
logger.add(sys.stdout, level='INFO', format=fmt)  # 咱们本地运行的时候，在控制台打印
logger.add('logs/auto_run.log',level='DEBUG',format=fmt,encoding='utf-8',enqueue=True,rotation='1 day')#写在日志文件里面
# logger.add('wxl.log', level='DEBUG', format=fmt, encoding='utf-8', enqueue=True, rotation='1 day',
# #            retention='10 days')  # 写在日志文件里面

def find_wars():
    ready_war = os.listdir(LOCAL_PATH)  # 读取本地目录下的war包
    if len(ready_war) == 0:
        logger.info('本地{}为空！'.format(LOCAL_PATH))
    else:
        ready_war_list = []
        file_path_list = []
        for root,dirs,files in os.walk(LOCAL_PATH):
            for file in files:
                if file.endswith('.war'):
                    file_path = os.path.join(root,file)
                    file_path_list.append(file_path)
                    file = file[:-4]
                    ready_war_list.append(file)
        if ready_war_list:
            logger.info('本地war包有：【{}】',ready_war_list)
            return ready_war_list,file_path_list

    logger.info('没有war包！')
    return 'a','b'

def parse_ini(node,file_path='conf.ini'):
    if not os.path.exists(file_path):
        logger.error('配置文件不存在，文件路径{}',file_path)
        raise  Exception('ini文件不存在')
    with open(file_path, encoding='utf-8')as fr:
        c = configparser.ConfigParser()
        c.read_file(fr)
        if node in c.sections():
            result = (dict(c[node]))
            return result
        logger.warning('配置文件【{}】节点不存在',node)




if __name__ == '__main__':
    # find_wars()
    print(parse_ini('local_path'))